﻿
package extremefx.i18n {
	/**
	 * @author Marcelo Volmaro
	 */
	internal class CCEastAsianLunisolar {
//		private const INITIAL_EPACT:int = 29; // at 1900
//		private static const _leapMonthCalc:Array = [0, 2, 0, 2, 2, 4, 5, 6, 7, 8, 9, 10];
		
		public static function _isLeapMonth (pYear:int, pMonth:int):Boolean {
			var goldenNumber:int = pYear % 19;

			var chu:Boolean = false;
			var leap:Boolean = false;
			var s:Number = 0;
			for (var y:int = 0; y < goldenNumber; y++) {
				for (var l:int = 0, m:int = 1; m <= pMonth; m++) {
					if (leap) {
						l += 30;
						leap = false;
						if (y == goldenNumber && m == pMonth) return true;
						
					} else {
						l += chu ? 30 : 29;
						chu = !chu;
						s += 30.44;
						if (s - l > 29) leap = true;
					}
				}
			}
			
			return false;
		}
		
		public static function _isLeapYear (pYear:int):Boolean {
			// FIXME: it is still wrong.
			var d:int = pYear % 19;
			switch (d) {
				case 0: case 3: case 6: case 9: case 11: case 14: case 17:
				return true;
				
			default:
				return false;
			}
		}
	}
}
